import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:wechat/chat/message_data.dart';

class MessageItem extends StatelessWidget {
  final MessageData message;
  const MessageItem({super.key, required this.message});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 64,
      decoration: const BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: BorderSide(width: 0.5, color: Color(0xFFd9d9d9)),
        ),
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            margin: const EdgeInsets.only(left: 13, right: 13),
            child: Image.network(
              message.avatar,
              width: 48,
              height: 48,
              fit: BoxFit.cover,
            ),
          ),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  message.title,
                  style: const TextStyle(
                    fontSize: 16,
                    color: Color(0xFF353535),
                  ),
                  maxLines: 1,
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 8),
                  child: Text(
                    message.subTitle,
                    style: const TextStyle(
                      fontSize: 14,
                      color: Color(0xFF999999),
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                )
              ],
            ),
          ),
          Container(
            alignment: Alignment.topLeft,
            margin: const EdgeInsets.only(right: 12, top: 12),
            child: Text(
              formatDate(
                message.time,
                [HH, ":", nn, ":", ss],
              ).toString(),
              style: const TextStyle(fontSize: 14, color: Color(0xFF999999)),
            ),
          )
        ],
      ),
    );
  }
}
